package com.dstation.service;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.dstation.dao.VideoDataAnalysisInfoMapper;
import com.dstation.domain.VideoInfo;
import com.dstation.domain.vo.AnalysisData;
import com.dstation.service.interf.IVideoDataAnalysisService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;


@Service
public class VideoDataAnalysisServiceImpl implements IVideoDataAnalysisService {


    @Resource
    private VideoDataAnalysisInfoMapper videoDataAnalysisMapper;




    @Override
    public List<AnalysisData> findBrowserData(long userId, int pageSize) {
        return videoDataAnalysisMapper.selectBrowserData(userId,pageSize);
    }

    @Override
    public List<AnalysisData> findLikedData(Long userId, int pageSize) {
        List<AnalysisData> data = videoDataAnalysisMapper.selectLikedData(userId, pageSize);
        for(int i=0;i<data.size();i++){
            VideoInfo cur=videoDataAnalysisMapper.selectVideoById(data.get(i).getVideoId());

            //填充数据

            data.get(i).setVideoTitle(cur.getVideoTitle());
            data.get(i).setVideoCoverImg(cur.getVideoCoverImg());
        }


        return data;
    }

    @Override
    public List<AnalysisData> findCollectData(long userId, int pageSize) {
        List<AnalysisData> data = videoDataAnalysisMapper.selectCollectData(userId, pageSize);
        for(int i=0;i<data.size();i++){
            VideoInfo cur=videoDataAnalysisMapper.selectVideoById(data.get(i).getVideoId());
            //填充数据

            data.get(i).setVideoTitle(cur.getVideoTitle());
            data.get(i).setVideoCoverImg(cur.getVideoCoverImg());
        }


        return data;
    }

    @Override
    public List<AnalysisData> findCommentData(long userId, int pageSize) {
        List<AnalysisData> data = videoDataAnalysisMapper.selectCommentData(userId, pageSize);
        for(int i=0;i<data.size();i++){
            VideoInfo cur=videoDataAnalysisMapper.selectVideoById(data.get(i).getVideoId());
            //填充数据

            data.get(i).setVideoTitle(cur.getVideoTitle());
            data.get(i).setVideoCoverImg(cur.getVideoCoverImg());
        }


        return data;
    }

    @Override
    public List<AnalysisData> findCoinData(long userId, int pageSize) {
        List<AnalysisData> data = videoDataAnalysisMapper.selectCoinData(userId, pageSize);
        for(int i=0;i<data.size();i++){
            VideoInfo cur=videoDataAnalysisMapper.selectVideoById(data.get(i).getVideoId());
            //填充数据

            data.get(i).setVideoTitle(cur.getVideoTitle());
            data.get(i).setVideoCoverImg(cur.getVideoCoverImg());
        }


        return data;
    }

    @Override
    public List<AnalysisData> findBulletChatData(long userId, int pageSize) {
        List<AnalysisData> data = videoDataAnalysisMapper.selectBulletChatData(userId, pageSize);
        for(int i=0;i<data.size();i++){
            VideoInfo cur=videoDataAnalysisMapper.selectVideoById(data.get(i).getVideoId());
            //填充数据

            data.get(i).setVideoTitle(cur.getVideoTitle());
            data.get(i).setVideoCoverImg(cur.getVideoCoverImg());
        }


        return data;
    }

    @Override
    public IPage<AnalysisData> findAllBrowserData(Long userId, Page<Object> objectPage) {
        IPage<AnalysisData> analysisDataIPage = videoDataAnalysisMapper.selectAllBrowser(userId, objectPage);

        List<AnalysisData> data=analysisDataIPage.getRecords();
        for(int i=0;i<data.size();i++){
            VideoInfo cur=videoDataAnalysisMapper.selectVideoById(data.get(i).getVideoId());
            //填充数据

            data.get(i).setVideoTitle(cur.getVideoTitle());
            data.get(i).setVideoCoverImg(cur.getVideoCoverImg());
        }
        analysisDataIPage.setRecords(data);


        return analysisDataIPage;
    }

    @Override
    public IPage<AnalysisData> findAllCommentData(Long userId, Page<Object> objectPage) {
        IPage<AnalysisData> analysisDataIPage = videoDataAnalysisMapper.selectAllComment(userId, objectPage);

        List<AnalysisData> data=analysisDataIPage.getRecords();
        for(int i=0;i<data.size();i++){
            VideoInfo cur=videoDataAnalysisMapper.selectVideoById(data.get(i).getVideoId());
            //填充数据

            data.get(i).setVideoTitle(cur.getVideoTitle());
            data.get(i).setVideoCoverImg(cur.getVideoCoverImg());
        }
        analysisDataIPage.setRecords(data);


        return analysisDataIPage;
    }

    @Override
    public IPage<AnalysisData> findAllBulletChatData(Long userId, Page<Object> objectPage) {
        IPage<AnalysisData> analysisDataIPage = videoDataAnalysisMapper.selectAllBulletChat(userId, objectPage);

        List<AnalysisData> data=analysisDataIPage.getRecords();
        for(int i=0;i<data.size();i++){
            VideoInfo cur=videoDataAnalysisMapper.selectVideoById(data.get(i).getVideoId());
            //填充数据

            data.get(i).setVideoTitle(cur.getVideoTitle());
            data.get(i).setVideoCoverImg(cur.getVideoCoverImg());
        }
        analysisDataIPage.setRecords(data);


        return analysisDataIPage;
    }

    @Override
    public IPage<AnalysisData> findAllLikeData(Long userId, Page<Object> objectPage) {
        IPage<AnalysisData> analysisDataIPage = videoDataAnalysisMapper.selectAllLike(userId, objectPage);

        List<AnalysisData> data=analysisDataIPage.getRecords();
        for(int i=0;i<data.size();i++){
            VideoInfo cur=videoDataAnalysisMapper.selectVideoById(data.get(i).getVideoId());
            //填充数据

            data.get(i).setVideoTitle(cur.getVideoTitle());
            data.get(i).setVideoCoverImg(cur.getVideoCoverImg());
        }
        analysisDataIPage.setRecords(data);


        return analysisDataIPage;
    }

    @Override
    public IPage<AnalysisData> findAllCoinData(Long userId, Page<Object> objectPage) {
        IPage<AnalysisData> analysisDataIPage = videoDataAnalysisMapper.selectAllCoin(userId, objectPage);

        List<AnalysisData> data=analysisDataIPage.getRecords();
        for(int i=0;i<data.size();i++){
            VideoInfo cur=videoDataAnalysisMapper.selectVideoById(data.get(i).getVideoId());
            //填充数据

            data.get(i).setVideoTitle(cur.getVideoTitle());
            data.get(i).setVideoCoverImg(cur.getVideoCoverImg());
        }
        analysisDataIPage.setRecords(data);


        return analysisDataIPage;
    }

    @Override
    public IPage<AnalysisData> findAllCollectData(Long userId, Page<Object> objectPage) {
        IPage<AnalysisData> analysisDataIPage = videoDataAnalysisMapper.selectAllCollect(userId, objectPage);

        List<AnalysisData> data=analysisDataIPage.getRecords();
        for(int i=0;i<data.size();i++){
            VideoInfo cur=videoDataAnalysisMapper.selectVideoById(data.get(i).getVideoId());
            //填充数据

            data.get(i).setVideoTitle(cur.getVideoTitle());
            data.get(i).setVideoCoverImg(cur.getVideoCoverImg());
        }
        analysisDataIPage.setRecords(data);


        return analysisDataIPage;
    }
}
